<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/7 0007
 * Time: 17:35
 */

namespace app\api\controller\v1\agent;


use app\api\controller\v1\Agent;
use app\currency\service\AgentRebateService;
use app\currency\service\DateService;

class Rebate extends Agent
{
    /**
     * 获取钱包页面数据
     * 余额、今日收益、本月收益、团队做收益、团队销售收益
     */
    public function index()
    {
        $result = [
            'balance' => $this->agent->balance + 0,
            'today' => AgentRebateService::getRoyaltyPrice($this->aid, 'all',date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')),
            'month' => AgentRebateService::getRoyaltyPrice($this->aid, 'all',DateService::beginMonth(),DateService::endMonth()),
            'team_service' => AgentRebateService::getRoyaltyPrice($this->aid,'service'),
            'team_sale' => AgentRebateService::getRoyaltyPrice($this->aid,'bind'),
        ];
        $this->success('获取成功！',$result);
    }

    /**
     * @param string $id day|month
     */
    public function read($id)
    {
        if($id === 'day')
        {
            list($start_at,$ent_at) = [date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')];
        } elseif ($id === 'month')
        {
            list($start_at,$ent_at) = [DateService::beginMonth(),DateService::endMonth()];
        } else {
            $this->error('不支持的请求！');
        }
        $result = [
            'total' => AgentRebateService::getRoyaltyPrice($this->aid, 'all',$start_at,$ent_at),
            'team_service' => AgentRebateService::getRoyaltyPrice($this->aid,'service',$start_at,$ent_at),
            'team_sale' => AgentRebateService::getRoyaltyPrice($this->aid,'bind',$start_at,$ent_at),
        ];
        $this->success('获取成功！',$result);
    }
}